package org.bt.common.validator.sign;

import org.bt.common.validator.aspect.NegativeOrZero;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Check that the number being validated is negative.
 *
 * @author tongw
 */
public class NegativeOrZeroValidatorForInteger implements ConstraintValidator<NegativeOrZero, Integer> {

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        // null values are valid
        if (value == null) {
            return true;
        }

        return NumberSignHelper.signum(value) <= 0;
    }
}
